<template>
  <div class="background">
    <div class="loginBox">
      <div class="title">Students Manage System</div>
      <div class="smallTitle">Beta</div>
      <div class="fields">
        <el-form :rules="rules" ref="loginForm" :model="loginForm">
          <el-form-item prop="username">
            <el-input type="text" autocomplete="false" v-model="loginForm.username" prefix-icon="el-icon-user"
              placeholder="请输入电话号码"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input type="password" autocomplete="false" v-model="loginForm.password" prefix-icon="el-icon-lock"
              placeholder="请输入密码" show-password>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <button class="loginBtn" @click="loginBtn">Login <i v-if="isLoading" class="el-icon-loading"></i></button>
      <div class="link"><a href="#">Forget password?</a></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        // username: '',
        // password:''
        username: "2020413539",
        password: "111"
      },
      rules: {
        mobile: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      isLoading: false,
    }
  },
  methods: {
    loginBtn() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.isLoading = true;
          this.$http({
            url: '/webapi/student/login',
            method: 'get',
            params: this.loginForm
          }).then(res => {
            if (res.code == 200) {
              sessionStorage.setItem('role', res.data.role);
              sessionStorage.setItem('userId', res.data.username);
              this.$http.get('/webapi/student/getStu/' + res.data.username).then(res => {
                sessionStorage.setItem('userInfo', JSON.stringify(res.data));
              }).catch(e => {
                this.$message.error(e.message);
              })
              //页面跳转
              setTimeout(() => {
                this.$message.success(res.msg);
                this.$router.replace('/home');
              }, 1000);
            } else {
              this.$message.error(res.msg);
            }
          }).catch(e => {
            this.$message.error(e);
            this.isLoading = false;
          })
        } else {
          this.$message.error("请输入所有字段");
          return false;
        }
      });
    }
  }

}
</script>

<style scoped>
.background {
  width: 100vw;
  justify-content: center;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  height: 100vh;
  /* 背景渐变色 - 原理2 */
  background: linear-gradient(-45deg, #b09ee9, #87bdd1, #a6d0ed, #b2a6e8,
      #c4b7d7);
  /* 背景尺寸 - 原理3 */
  /* background-size: 600% 600%; */
  /* 循环动画 - 原理4 */
  /* animation: gradientBG 5s ease infinite; */
}

@keyframes gradientBG {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

.loginBox {
  width: 430px;
  height: 500px;
  margin: 60px auto;
  padding: 30px 35px 20px 35px;
  border-radius: 10px;
  background: rgb(239, 232, 232);
  /* background: radial-gradient(circle, #d3cee2, #c3d8df, #dde3e8, #dedde5,
        #e1daeb); */
  box-shadow: 0 20px 30px rgba(0, 0, 0, 0.33);
}


.title {
  text-align: center;
  font-size: 28px;
  padding-top: 24px;
  letter-spacing: 0.5px;
}

.smallTitle {
  text-align: center;
  font-size: 15px;
  padding-top: 7px;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-weight: bold;
}

.fields {
  width: 100%;
  padding: 100px 5px 30px 0;
}

.fields input {
  border: none;
  outline: none;
  width: 90%;
  background: none;
  font-size: 18px;
  font-family: 'Lato', sans-serif;
  color: rgb(0, 0, 0);
  padding: 10px 10px 10px 5px;
}

.username,
.password {
  display: block;
  border-bottom: 1px solid #b3b3b3;
  margin-bottom: 30px;
}

.loginBtn {
  outline: none;
  border: none;
  cursor: pointer;
  width: 100%;
  height: 60px;
  border-radius: 5px;
  font-size: 22px;
  font-family: 'Lato', sans-serif;
  color: rgb(0, 0, 0);
  text-align: center;
  letter-spacing: 1px;
  background: radial-gradient(circle, #cfc2db,
      #d2c9da,
      #d0c8d7,
      #ded9e3,
      #d1c8da);
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.loginBtn:hover {
  background: radial-gradient(circle, #eae6ee, #ded9e3,
      #dfd9e5,
      #d2c9da,
      #cfc2db);
}

.loginBtn:active {
  background: radial-gradient(circle, #cfc2db,
      #d2c9da,
      #dfd9e5,
      #ded9e3,
      #eae6ee);
}

.link {
  padding-top: 20px;
  text-align: center;
}

.link a {
  text-decoration: none;
  color: rgb(0, 0, 0);
  font-size: 20px;
}
</style>